package com.jiantong.work.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * Created by niufei on 2017/4/13.
 * 屠宰检疫报表实体类
 */
@Data
public class ButcherReportsForm implements Serializable{

    private static final ObjectMapper objectMapper = JsonMapper.nonEmptyMapper().getMapper();

    private static final long serialVersionUID = -8040580059901570042L;

    /**
     * 主键id
     */
    private Long id;

    /**
     * 申报id--屠宰
     */
    private Long reportId;

    /**
     * 申报号--屠宰
     */
    private String reportNumber;

    /**
     * 申报id--入场
     */
    private Long admissionReportId;

    /**
     * 申报号--入场
     */
    private String admissionReportNumber;

    /**
     * 申报人id
     */
    private Long applyUserId;

    /**
     * 申报人name
     */
    private String applyUserName;

    /**
     * 养殖场id
     */
    private Long sourceId;

    /**
     * 养殖场名称
     */
    private String sourceName;

    /**
     * 货主
     */
    private String owner;

    /**
     * 产品类型
     */
    private Integer productType;

    /**
     * 单位
     */
    private Integer unit;

    /**
     * 入场数量
     */
    private Integer quantity;

    /**
     * 入场合格数
     */
    private Integer qualifiedQuantity;

    /**
     * 入场不合格数
     */
    private Integer unqualifiedQuantity;

    /**
     * 《入场无害化处理通知单》主键id
     */
    private Long admissionHarmlessId;

    /**
     * 《入场无害化处理通知单》编号
     */
    private String admissionHarmlessNumber;

    /**
     * 是否佩戴规定的畜禽标识0:否;1:是;默认1
     */
    private Integer hasAnimalIdentify;

    /**
     * 临床检查
     */
    private Integer clinicalExamination;

    /**
     * 是否本地
     */
    private Integer isLocal;

    /**
     * 屠宰场id
     */
    private Long butcherFactoryId;

    /**
     * 屠宰场名称
     */
    private String butcherFactoryName;

    /**
     * 官方兽医id
     */
    private Long vetUserId;

    /**
     * 官方兽医名称(就是当前登录人)
     */
    private String vetUserName;

    /**
     * 宰前合格数
     */
    private Integer beforeSlaughterQualifiedQuantity;

    /**
     * 宰前不合格数
     */
    private Integer beforeSlaughterUnqualifiedQuantity;

    /**
     * 宰前检查无害化处理ID
     */
    private Long beforeSlaughterHarmlessId;

    /**
     * 宰前检查无害化处理编号
     */
    private String beforeSlaughterHarmlessNumber;

    /**
     * 同步检疫合格数
     */
    private Integer syncQualifiedQuantity;

    /**
     * 同步检疫不合格数(公斤)
     */
    private Float syncUnqualifiedQuantity;

    /**
     * 同步检疫无害化ID
     */
    private Long syncSlaughterHarmlessId;

    /**
     * 同步检疫无害化编号
     */
    private String syncSlaughterHarmlessNumber;

    /**
     * 检疫合格证编号
     */
    private String quarantineCertNumber;

    /**
     *
     */
    private Map<String , Map<String , String>> quarantineCertPhotoMap;

    /**
     * 检疫合格证
     */
    @JsonIgnore
    private String quarantineCertPhoto;

    /**
     * 屠宰检疫合格证
     */
    private String slaughterQuarantineCertNumber;

    /**
     * 申报日期
     */
    private Date reportDate;

    /**
     *《入场无害化处理通知单》编号 处理方式
     * 不存数据库
     */
    private Integer admissionHarmlessTreatment;

    /**
     * 《入场无害化处理通知单》编号 当前状态
     *  不存数据库
     */
    private Integer admissionHarmlessStatus;

    /**
     * 宰前检查无害化处理方式
     */
    private Integer beforeSlaughterHarmlessTreatment;

    /**
     * 宰前检查无害化处理状态
     */
    private Integer beforeSlaughterHarmlessStatus;

    /**
     * 同步检疫无害化方式
     */
    private Integer syncSlaughterHarmlessTreatment;

    /**
     * 同步检疫无害化状态
     */
    private Integer syncSlaughterHarmlessStatus;


    public void setQuarantineCertPhoto(String quarantineCertPhoto){
        this.quarantineCertPhoto = quarantineCertPhoto;
        if(Strings.isNullOrEmpty(quarantineCertPhoto)){
            this.quarantineCertPhotoMap = Maps.newHashMap();;
        }else {
            try {
                this.quarantineCertPhotoMap = objectMapper.readValue(quarantineCertPhoto, new TypeReference<Map<String , Map<String , String>>>(){});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }

    public void setQuarantineCertPhotoMap(Map<String , Map<String , String>> quarantineCertPhotoMap){
        this.quarantineCertPhotoMap = quarantineCertPhotoMap;
        if(quarantineCertPhotoMap == null || quarantineCertPhotoMap.isEmpty()){
            this.quarantineCertPhoto = null;
        }else {
            try {
                this.quarantineCertPhoto = objectMapper.writeValueAsString(quarantineCertPhotoMap);
            } catch (JsonProcessingException e) {
                //ignore this fuck JsonProcessingException
            }
        }
    }
}
